﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AndersLiu.Reflector.Properties;
using System.Reflection;
using System.Diagnostics;

namespace AndersLiu.Reflector.Program.UI
{
    public partial class AboutDialog : Form
    {
        public AboutDialog()
        {
            InitializeComponent();
        }

        private void AboutDialog_Load(object sender, EventArgs e)
        {
            this.Text = string.Format("About {0}", Application.ProductName);

            picLogo.Image = Resources.ReflectorIcon.ToBitmap();
            lblApplicationTitle.Text = Application.ProductName;

            lblVersion.Text = string.Format("Version: {0}", Application.ProductVersion.ToString());

            var assembly = Assembly.GetExecutingAssembly();
            var copyrightAttributes = (AssemblyCopyrightAttribute[])assembly
                .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

            lblCopyright.Text = copyrightAttributes != null && copyrightAttributes.Length == 1
                ? copyrightAttributes[0].Copyright
                : "[No copyright info]";

            var companyAttributes = (AssemblyCompanyAttribute[])assembly
                .GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);

            lblAuthor.Text = companyAttributes != null && companyAttributes.Length == 1
                ? string.Format("Developed By {0}", companyAttributes[0].Company)
                : "[No developer/company info]";

            lblWebsite.Text = "http://reflector.codeplex.com/";
            lblWebsite.LinkClicked += delegate { Process.Start(lblWebsite.Text); };

            var refs = assembly.GetReferencedAssemblies();
            foreach (var a in refs)
            {
                if (a.Name == "Microsoft.Cci.MetadataModel")
                    lblCciVersion.Text = string.Format("[Microsoft CCI Metadata Version: {0}]", a.Version);
            }
        }
    }
}
